﻿using System;
using System.Web.Script.Serialization;

namespace IPCChannel
{
    public enum IPCMessageTypes
    {
        IssuanceMessage,
        SetupMessage,
        PresentationMessage
    }

    [Serializable]
    public abstract class IPCMessage
    {
        public string SenderIp;
        public int SenderPort;
        public IPCMessageTypes MessageType;

        public IPCMessage()
        {
        }

        protected IPCMessage(IPCMessageTypes messageType)
        {
            MessageType = messageType;
        }

        public static string Serialize<T>(T msgObj)
        {
            return new JavaScriptSerializer().Serialize(msgObj);
        }

        public abstract string Serialize();

        public static T Deserialize<T>(string jsonMsg)
        {
            return new JavaScriptSerializer().Deserialize<T>(jsonMsg);
        }
    }
}
